package com.sikao.app.ui;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;

import com.sikao.app.R;
import com.sikao.app.app.AppManager;
import com.sikao.app.app.MyApplication;
import com.sikao.app.utils.SharepreferenceUtil;


/**
 * 第一个activity，在此判断是否为第一次启动，是跳到导航页，不是则跳到FirstActivity
 */
public class MainActivity extends Activity {

	private ImageView imageView;
	private SharepreferenceUtil sp;
	public AppManager appManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		//DimenTool.gen();
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		//禁止横屏
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		appManager = AppManager.getAppManager();
		appManager.addActivity(this);
		initData();
		initView();
		initListener();
		init();
	}

	protected void initData() {
		sp = SharepreferenceUtil.getInstance(MyApplication.getInstance());
	}

	protected void initView() {
		imageView = (ImageView) findViewById(R.id.imageView);
	}

	protected void initListener() {

	}

	protected void init() {

	}

	@Override
	protected void onResume() {
		super.onResume();
		Log.d("ActivityName", this.getClass().getName() + "---------onResume ");
		AlphaAnimation animation = new AlphaAnimation(1.0f, 1.0f);
		animation.setDuration(500);
		animation.setAnimationListener(new Animation.AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				String isFirst = sp.getString("isFirst");
				Intent intent = new Intent();
				 if (isFirst == null || isFirst.equals("")) {
					 intent.setClass(MainActivity.this, GuidePageActivity.class);
					 startActivity(intent);
				} else {
					 intent.setClass(MainActivity.this, FirstActivity.class);
					 startActivity(intent);
				}

			}

			@Override
			public void onAnimationRepeat(Animation animation) {

			}
		});
		imageView.startAnimation(animation);
	}

	@Override
	protected void onStart() {
		super.onStart();
		Log.d("ActivityName", this.getClass().getName() + "---------onStart ");
	}

	@Override
	protected void onRestart() {
		super.onRestart();
		Log.d("ActivityName", this.getClass().getName() + "---------onRestart ");
	}

	@Override
	protected void onPause() {
		super.onPause();
		Log.d("ActivityName", this.getClass().getName() + "---------onPause ");
	}

	@Override
	protected void onStop() {
		super.onStop();
		Log.d("ActivityName", this.getClass().getName() + "---------onPause ");
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		appManager.finishActivity(this);
		Log.d("ActivityName", this.getClass().getName() + "---------onDestroy ");
	}

	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		Log.d("finalize", this.getClass().getName());
	}

}
